Ext.define('qjtravel.view.Spotsign', {
    extend: 'Ext.Panel',
    xtype: 'spotsign',
    requires: [
        "Ext.plugin.ListPaging",
        "Ext.plugin.PullRefresh",
        'Ext.pintrest.dataview.Pintrest',
        'qjtravel.view.MyPintrestItem' // only if we would like to customize the look of list items
    ],
    config: {
        background:"#fff",
        productListStore: 'qjtravel.store.ProductList',
        items: [
            {
                xtype: 'titlebar',
                title: '照片墙',
                docked: 'top',
                inline: true,
                items: [
                    {
                        xtype: 'button',
                        align: 'right',
                        id: 'scan',
                        text: '拍照'
                    }
                ]
            }
        ],
        productList: {
            id: 'productlist',
            scrollable: true,
            defaultType: 'mypinitem',
            top: 2,
            bottom: 0,
            left: 2,
            right: 0,
            disableSelection: false,
            maxNumColumns: 4,
            minNumColumns: 3,
            maxColumnWidth: 300,
            minSideSpacing: 0,
            columnMargin: 2,
            rowMargin: 5,
            emptyText: "<div style='margin: 100px auto;color: #ccc;font-size: 16px;'><img src='resources/images/null.png'/><br>亲!请上传图片......</div>",
            listeners: {
                painted: function (list) {
                    var s = Ext.create("qjtravel.store.ProductList");
//                    s.getProxy().setExtraParam("udid", 123);
                    s.getProxy().setExtraParam("udid", localStorage.getItem("udid"));
                    s.load();
                    this.setStore(s);

                }
            },
            plugins:[
                {
                    xclass: 'Ext.plugin.PullRefresh',
                    pullRefreshText: '下拉可以更新',
                    releaseRefreshText: '松开开始更新',
                    style: 'top:12px',
                    loadingText: '正在刷新……',
                    refreshFn: function (loaded, arguments) {
                      //  Ext.getCmp("showmsg").hide();
                        loaded.getList().getStore().loadPage(1, {
                            callback: function (record, operation, success) {
                                Ext.Viewport.unmask();
                            }, scope: this });
                    }
                },
                {
                    xclass: 'Ext.plugin.ListPaging',
                    //loadMoreText: '<h2 style="text-align: center; padding-top: 20px; padding-bottom: 20px;font-size: 13px">上拉加载更多</h2>',
                   // noMoreRecordsText: '<h2 style="text-align: center; padding-top: 20px; padding-bottom: 20px;font-size: 13px">没有了</h2>',
                    autoPaging: true
                }
            ]
        }
    },
    initialize: function () {
        var me = this;
        me.add(me.getProductList());
       // me.add({xtype:"panel",id:"showmsg",docked:"bottom",hidden:true,html:"<div style='width: 100%;height: 20px;line-height: 20px;text-align: center'>没有更多了</div>"});
    },
    applyTitlebar: function (config) {
        var toolbar = Ext.factory(config, Ext.TitleBar, this.getTitlebar());
        return toolbar;
    },
    applyProductList: function (config) {
        var productList = Ext.factory(config, Ext.Pintrest, this.getProductList());
        productList.element.on('tap', this.addProductToCart, this);
        return productList;
    },

    applyProductListStore: function (storeId) {
        var store = Ext.create(storeId);
        return store;
    },

    addProductToCart: function (evt, dom) {
        Ext.Viewport.mask({type:"loadmask"});
        console.log(document.getElementsByTagName("body")[0].style.backgroundColor="#fff")
        //TODO list item tap event code
        //WARING: This ListPaging Plugins float item top
        //console.log(evt);
        console.log(dom);
        var picSrc=dom.src,htmlStr="";

        if(picSrc==undefined){
            setTimeout(function(){
                cordova.exec(function (msg) {
                }, function (msg) {
                }, "Messages", "showMsg", ["加载失败,请重试"]);
                Ext.Viewport.unmask();
            },700)
        }else{
            htmlStr="<div style='margin: 0px auto;width: 100%;height:100%;background-color:#FFFFFF'></div>" +
                "<div style='position: absolute;z-index:999;top: 0px;left: 0px;width: 100%;height: 100%; background: url(\""+picSrc+"\") no-repeat; background-position:center center; background-size:400px auto;'></div>";
            Ext.Viewport.unmask();
        }
        Ext.Viewport.animateActiveItem("imgShowView",{type:"pop",direction:"center"})
        /*Ext.getCmp("showPic").setHtml("<div style='margin: 0px auto;width: 100%;height:100%;background-color: #000;opacity: 0.4;'></div>" +
            "<div style='position: absolute;z-index:999;top: 0px;left: 0px;width: 100%;height: 100%; background: url(\""+picSrc+"\") no-repeat; background-position:center center; background-size:400px auto;'></div>")*/
        Ext.getCmp("showPic").setHtml(htmlStr);

    }
});
